package com.字节流;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/*字节流写输入的三种方式*/
public class FileOutputStreamDemo2 {
    public static void main(String[] args) throws IOException {
        //构造方法1
        FileOutputStream fos1 = new FileOutputStream("idea_test\\a.txt");
        //构造方法2
        /*File file = new File("idea_test\\a.txt");
        FileOutputStream fos2 = new FileOutputStream(file);*/

        /*写输入*/
        //1.void write(int b):将指定字节写入此文件输出流。
        fos1.write(97);
        fos1.write(98);
        fos1.write(99);
        fos1.write(100);
        fos1.write(" ".getBytes());
        System.out.println(" ".getBytes()); //[B@41629346

        //2.void write(byte[] b):将b.length字节从指定的字节数组写入此文件输出流。
        /*byte[] bys = {117,118,119,120};
        fos1.write(bys);*/
        //2.String类还有一种方法：byte[] getBytes():返回字符串对应的数组
        byte[] bys = "uvwx".getBytes();
        fos1.write(bys);
        fos1.write(" ".getBytes());

        //3.void write(byte[] b,int off,int len)：将len字节从指定的字节数组下标off开始，写长度为len的数据。
        fos1.write(bys,1,3);

    }
}
